Skip to content

fix(lambda-nodejs): use powershell for spawn steps on Windows#37412

Merged
mergify[bot] merged 6 commits intomainfrom
fix/lambda-nodejs-windows-spawn-einval
Mar 30, 2026
Merged

fix(lambda-nodejs): use powershell for spawn steps on Windows#37412
mergify[bot] merged 6 commits intomainfrom
fix/lambda-nodejs-windows-spawn-einval

Conversation

@Abogical
Copy link
Copy Markdown
Member

@Abogical Abogical commented Mar 30, 2026

Issue

Closes #37387

Reason for this change

CDK 2.245.0 introduced direct spawnSync for local bundling (9bf4263). On Windows with Node 22+, spawnSync npx.cmd fails with EINVAL because Node's spawn implementation on Windows cannot resolve .cmd shims through the direct spawn path.

Description of changes

For spawn steps on win32, route the command through powershell.exe -NoProfile -Command instead of calling the executable directly. Shell steps (cmd /c) remain unchanged.

Description of how you validated changes

  • Reproduced the original EINVAL error on a Windows EC2 instance
  • Applied the fix and confirmed bundling succeeds as integ tests aws-lambda-nodejs\test\integ.compilations.ts and aws-lambda-nodejs\test\integ.function.ts
  • Added unit tests:
    • Local bundling on Windows uses powershell for spawn steps — verifies esbuild invocation goes through powershell with properly escaped args
    • Local bundling on Windows uses cmd for shell steps — verifies shell hooks still use cmd while spawn steps use powershell

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

On Windows with Node 22+, direct spawnSync of npx.cmd fails with
EINVAL. This routes spawn steps through powershell.exe on win32,
while keeping shell steps on cmd.exe unchanged.

Closes #37387
@github-actions github-actions bot added bug This issue is a bug. p0 star-contributor [Pilot] contributed between 25-49 PRs to the CDK labels Mar 30, 2026
@aws-cdk-automation aws-cdk-automation requested a review from a team March 30, 2026 12:11
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 30, 2026
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@Abogical Abogical marked this pull request as ready for review March 30, 2026 12:44
@Abogical Abogical added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Mar 30, 2026
@Abogical Abogical added the pr/do-not-merge This PR should not be merged at this time. label Mar 30, 2026
…awn steps

Use powershellEscape ('' for single quotes) instead of posixShellEscape
('\'' for single quotes) when routing spawn steps through PowerShell on
Windows. Also prepend the & call operator so PowerShell treats the first
quoted token as a command invocation rather than a string expression.
@Abogical Abogical changed the title fix(aws-lambda-nodejs): use powershell for spawn steps on Windows fix(lambda-nodejs): use powershell for spawn steps on Windows Mar 30, 2026
@Abogical Abogical removed the pr/do-not-merge This PR should not be merged at this time. label Mar 30, 2026
@aws-cdk-automation aws-cdk-automation dismissed their stale review March 30, 2026 14:46

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 30, 2026

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 30, 2026

Merge Queue Status

  • Entered queue2026-03-30 15:18 UTC · Rule: default-squash
  • Checks passed · in-place
  • Merged2026-03-30 22:12 UTC · at 21b8345483af764dc16f6f7911a27e2256214abf

This pull request spent 6 hours 53 minutes 27 seconds in the queue, including 45 minutes 17 seconds running CI.

Required conditions to merge

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 30, 2026

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit a92105c into main Mar 30, 2026
19 of 20 checks passed
@mergify mergify bot deleted the fix/lambda-nodejs-windows-spawn-einval branch March 30, 2026 22:12
@github-actions
Copy link
Copy Markdown
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug This issue is a bug. contribution/core This is a PR that came from AWS. p0 pr-linter/exempt-integ-test The PR linter will not require integ test changes star-contributor [Pilot] contributed between 25-49 PRs to the CDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aws-lambda: Error when bundling due to spawnSync

3 participants